package com.huangsm.concurrence.exchanger;

import java.util.concurrent.Exchanger;

/**
 * 交换机
 * java.util.concurrent.Exchanger 类表示一种两个线程可以进行互相交换对象的会和点。
 * @author huang
 * @date 2019/2/14
 */
public class ExchangerDemo {
    public static void main(String[] args) {
        Exchanger exchanger = new Exchanger();

        ExchangerRunnable exchangerRunnable1 =
                new ExchangerRunnable(exchanger, "A");

        ExchangerRunnable exchangerRunnable2 =
                new ExchangerRunnable(exchanger, "B");

        new Thread(exchangerRunnable1).start();
        new Thread(exchangerRunnable2).start();
    }

}
